// ignore: depend_on_referenced_packages
import 'package:flutter_test/flutter_test.dart';
import '../pdf/implementation/exporting/pdf_text_extractor/glyph.dart';
import '../pdf/implementation/exporting/pdf_text_extractor/graphic_object_data.dart';
import '../pdf/implementation/exporting/pdf_text_extractor/graphic_object_data_collection.dart';
import '../pdf/implementation/exporting/pdf_text_extractor/page_resource_loader.dart';
import '../pdf/implementation/exporting/pdf_text_extractor/xobject_element.dart';
import '../pdf/implementation/io/pdf_constants.dart';
import '../pdf/implementation/primitives/pdf_array.dart';
import '../pdf/implementation/primitives/pdf_dictionary.dart';
import '../pdf/implementation/primitives/pdf_name.dart';
import '../pdf/implementation/primitives/pdf_number.dart';
import '../pdf/implementation/primitives/pdf_reference_holder.dart';
import '../pdf/implementation/primitives/pdf_stream.dart';

// ignore: public_member_api_docs
void xObjectElementTest() {
  group('xobject_element.dart - coverage test', () {
    test('xobject_element', () {
      final PdfDictionary dictionary = PdfDictionary();
      dictionary[PdfDictionaryProperties.subtype] = PdfName('Form');
      final XObjectElement element = XObjectElement(dictionary, 'test');
      // expect(element.objectName, 'test',
      //     reason: 'failed to priserve object name');
      // expect(element.objectType, 'Form',
      //     reason: 'failed to priserve object type');
      expect(element.render(null), null, reason: 'failed to return null');
    });
    test('xobject render - 1', () {
      final PdfStream dictionary = PdfStream();
      dictionary.data = <int>[
        37,
        32,
        67,
        104,
        97,
        110,
        103,
        101,
        32,
        99,
        111,
        45,
        111,
        114,
        100,
        105,
        110,
        97,
        116,
        101,
        32,
        115,
        121,
        115,
        116,
        101,
        109,
        32,
        116,
        111,
        32,
        108,
        101,
        102,
        116,
        47,
        116,
        111,
        112,
        46,
        13,
        10,
        49,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        49,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        49,
        49,
        46,
        49,
        48,
        32,
        32,
        99,
        109,
        13,
        10,
        47,
        68,
        101,
        118,
        105,
        99,
        101,
        82,
        71,
        66,
        32,
        67,
        83,
        13,
        10,
        47,
        68,
        101,
        118,
        105,
        99,
        101,
        82,
        71,
        66,
        32,
        99,
        115,
        13,
        10,
        48,
        32,
        48,
        32,
        48,
        32,
        114,
        103,
        13,
        10,
        13,
        10,
        47,
        101,
        48,
        55,
        97,
        48,
        55,
        49,
        98,
        45,
        51,
        101,
        97,
        51,
        45,
        52,
        52,
        56,
        50,
        45,
        97,
        102,
        101,
        97,
        45,
        52,
        54,
        55,
        50,
        54,
        99,
        101,
        101,
        51,
        98,
        98,
        101,
        32,
        49,
        48,
        46,
        48,
        48,
        32,
        84,
        102,
        13,
        10,
        66,
        84,
        13,
        10,
        48,
        32,
        84,
        114,
        13,
        10,
        46,
        48,
        48,
        32,
        84,
        99,
        13,
        10,
        46,
        48,
        48,
        32,
        84,
        119,
        13,
        10,
        49,
        48,
        48,
        46,
        48,
        48,
        32,
        84,
        122,
        13,
        10,
        46,
        48,
        48,
        32,
        50,
        46,
        49,
        49,
        32,
        84,
        100,
        13,
        10,
        49,
        49,
        46,
        49,
        48,
        32,
        84,
        76,
        13,
        10,
        40,
        108,
        41,
        39,
        13,
        10,
        69,
        84,
        13,
        10
      ];
      dictionary[PdfDictionaryProperties.subtype] = PdfName('Form');
      dictionary[PdfDictionaryProperties.resources] =
          PdfReferenceHolder(PdfDictionary());
      final PdfArray matrix = PdfArray();
      matrix.add(PdfNumber(0.9));
      matrix.add(PdfNumber(0.9));
      matrix.add(PdfNumber(-1.0606601717798214));
      matrix.add(PdfNumber(1.7677669529663689));
      matrix.add(PdfNumber(15.0));
      matrix.add(PdfNumber(25.0));
      dictionary[PdfDictionaryProperties.matrix] = matrix;
      final XObjectElement element = XObjectElement(dictionary, 'test');
      final GraphicsObject g = GraphicsObject();
      final PdfPageResources resources = PdfPageResources();
      final GraphicStateCollection graphicsStates = GraphicStateCollection();
      final GraphicObjectDataCollection objects = GraphicObjectDataCollection();
      objects.push(GraphicObjectData());
      const double currentPageHeight = 550;
      final List<Glyph> glyphList = <Glyph>[];
      try {
        element.renderTextElement(g, resources, graphicsStates, objects,
            currentPageHeight, glyphList);
      } catch (e) {
        expect(true, true, reason: 'Coverage test 1');
      }
    });
    test('xobject render - 2', () {
      final PdfStream dictionary = PdfStream();
      dictionary.data = <int>[
        37,
        32,
        67,
        104,
        97,
        110,
        103,
        101,
        32,
        99,
        111,
        45,
        111,
        114,
        100,
        105,
        110,
        97,
        116,
        101,
        32,
        115,
        121,
        115,
        116,
        101,
        109,
        32,
        116,
        111,
        32,
        108,
        101,
        102,
        116,
        47,
        116,
        111,
        112,
        46,
        13,
        10,
        49,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        49,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        49,
        49,
        46,
        49,
        48,
        32,
        32,
        99,
        109,
        13,
        10,
        47,
        68,
        101,
        118,
        105,
        99,
        101,
        82,
        71,
        66,
        32,
        67,
        83,
        13,
        10,
        47,
        68,
        101,
        118,
        105,
        99,
        101,
        82,
        71,
        66,
        32,
        99,
        115,
        13,
        10,
        48,
        32,
        48,
        32,
        48,
        32,
        114,
        103,
        13,
        10,
        13,
        10,
        47,
        101,
        48,
        55,
        97,
        48,
        55,
        49,
        98,
        45,
        51,
        101,
        97,
        51,
        45,
        52,
        52,
        56,
        50,
        45,
        97,
        102,
        101,
        97,
        45,
        52,
        54,
        55,
        50,
        54,
        99,
        101,
        101,
        51,
        98,
        98,
        101,
        32,
        49,
        48,
        46,
        48,
        48,
        32,
        84,
        102,
        13,
        10,
        66,
        84,
        13,
        10,
        48,
        32,
        84,
        114,
        13,
        10,
        46,
        48,
        48,
        32,
        84,
        99,
        13,
        10,
        46,
        48,
        48,
        32,
        84,
        119,
        13,
        10,
        49,
        48,
        48,
        46,
        48,
        48,
        32,
        84,
        122,
        13,
        10,
        46,
        48,
        48,
        32,
        50,
        46,
        49,
        49,
        32,
        84,
        100,
        13,
        10,
        49,
        49,
        46,
        49,
        48,
        32,
        84,
        76,
        13,
        10,
        40,
        108,
        41,
        39,
        13,
        10,
        69,
        84,
        13,
        10
      ];
      dictionary[PdfDictionaryProperties.subtype] = PdfName('Form');
      dictionary[PdfDictionaryProperties.resources] =
          PdfReferenceHolder(PdfDictionary());
      final PdfArray matrix = PdfArray();
      matrix.add(PdfNumber(1));
      matrix.add(PdfNumber(0));
      matrix.add(PdfNumber(-1.0606601717798214));
      matrix.add(PdfNumber(1.7677669529663689));
      matrix.add(PdfNumber(15.0));
      matrix.add(PdfNumber(25.0));
      dictionary[PdfDictionaryProperties.matrix] = matrix;
      final XObjectElement element = XObjectElement(dictionary, 'test');
      final GraphicsObject g = GraphicsObject();
      final PdfPageResources resources = PdfPageResources();
      final GraphicStateCollection graphicsStates = GraphicStateCollection();
      final GraphicObjectDataCollection objects = GraphicObjectDataCollection();
      objects.push(GraphicObjectData());
      const double currentPageHeight = 550;
      final List<Glyph> glyphList = <Glyph>[];
      try {
        element.renderTextElement(g, resources, graphicsStates, objects,
            currentPageHeight, glyphList);
      } catch (e) {
        expect(true, true, reason: 'Coverage test 1');
      }
    });
    test('xobject render - 3', () {
      final PdfStream dictionary = PdfStream();
      dictionary.data = <int>[
        37,
        32,
        67,
        104,
        97,
        110,
        103,
        101,
        32,
        99,
        111,
        45,
        111,
        114,
        100,
        105,
        110,
        97,
        116,
        101,
        32,
        115,
        121,
        115,
        116,
        101,
        109,
        32,
        116,
        111,
        32,
        108,
        101,
        102,
        116,
        47,
        116,
        111,
        112,
        46,
        13,
        10,
        49,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        49,
        46,
        48,
        48,
        32,
        46,
        48,
        48,
        32,
        49,
        49,
        46,
        49,
        48,
        32,
        32,
        99,
        109,
        13,
        10,
        47,
        68,
        101,
        118,
        105,
        99,
        101,
        82,
        71,
        66,
        32,
        67,
        83,
        13,
        10,
        47,
        68,
        101,
        118,
        105,
        99,
        101,
        82,
        71,
        66,
        32,
        99,
        115,
        13,
        10,
        48,
        32,
        48,
        32,
        48,
        32,
        114,
        103,
        13,
        10,
        13,
        10,
        47,
        101,
        48,
        55,
        97,
        48,
        55,
        49,
        98,
        45,
        51,
        101,
        97,
        51,
        45,
        52,
        52,
        56,
        50,
        45,
        97,
        102,
        101,
        97,
        45,
        52,
        54,
        55,
        50,
        54,
        99,
        101,
        101,
        51,
        98,
        98,
        101,
        32,
        49,
        48,
        46,
        48,
        48,
        32,
        84,
        102,
        13,
        10,
        66,
        84,
        13,
        10,
        48,
        32,
        84,
        114,
        13,
        10,
        46,
        48,
        48,
        32,
        84,
        99,
        13,
        10,
        46,
        48,
        48,
        32,
        84,
        119,
        13,
        10,
        49,
        48,
        48,
        46,
        48,
        48,
        32,
        84,
        122,
        13,
        10,
        46,
        48,
        48,
        32,
        50,
        46,
        49,
        49,
        32,
        84,
        100,
        13,
        10,
        49,
        49,
        46,
        49,
        48,
        32,
        84,
        76,
        13,
        10,
        40,
        108,
        41,
        39,
        13,
        10,
        69,
        84,
        13,
        10
      ];
      dictionary[PdfDictionaryProperties.subtype] = PdfName('Form');
      dictionary[PdfDictionaryProperties.resources] =
          PdfReferenceHolder(PdfDictionary());
      final PdfArray matrix = PdfArray();
      matrix.add(PdfNumber(-0.9));
      matrix.add(PdfNumber(1.9));
      matrix.add(PdfNumber(-1.0606601717798214));
      matrix.add(PdfNumber(1.7677669529663689));
      matrix.add(PdfNumber(15.0));
      matrix.add(PdfNumber(25.0));
      dictionary[PdfDictionaryProperties.matrix] = matrix;
      final XObjectElement element = XObjectElement(dictionary, 'test');
      final GraphicsObject g = GraphicsObject();
      final PdfPageResources resources = PdfPageResources();
      final GraphicStateCollection graphicsStates = GraphicStateCollection();
      final GraphicObjectDataCollection objects = GraphicObjectDataCollection();
      objects.push(GraphicObjectData());
      const double currentPageHeight = 550;
      final List<Glyph> glyphList = <Glyph>[];
      try {
        element.renderTextElement(g, resources, graphicsStates, objects,
            currentPageHeight, glyphList);
        expect(g.transformMatrix!.m11 == 0.9 && g.transformMatrix!.m12 == 0.0,
            true,
            reason: 'Input range is not valid');
      } catch (e) {
        expect(true, true, reason: 'Coverage test 1');
      }
    });
  });
  group('String Unescape', () {
    test('test 1', () {
      // ignore: unnecessary_string_escapes
      const String text = '0-9, A-Z,a dash\(-\),a dot\(.\),,/,+,%, SPACE';
      final String result = unescape(text);
      expect(result, '0-9, A-Z,a dash(-),a dot(.),,/,+,%, SPACE',
          reason: 'Invalid character');
    });
    test('test 2', () {
      const String text =
          // ignore: unnecessary_string_escapes
          '\(0x18\) EM \(0x19\) SUB \(0x1A\) ESC \(0x1B\) FS \(0x1C\) GS \(0x1D\) RS \(0x1E\) US';
      final String result = unescape(text);
      expect(result,
          '(0x18) EM (0x19) SUB (0x1A) ESC (0x1B) FS (0x1C) GS (0x1D) RS (0x1E) US',
          reason: 'Invalid character');
    });
    test('test 3', () {
      const String text =
          // ignore: unnecessary_string_escapes
          '''\(0x1F\) SPACE \(0x20\) " ! # % & \' \( \) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = \> ? @ A''';
      final String result = unescape(text);
      expect(result,
          '(0x1F) SPACE (0x20) " ! # % & \' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A',
          reason: 'Invalid character');
    });
  });
}
